home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH3 / SRC / RICH.FRM < prev    next >
Text File  |  1996-01-29  |  15KB  |  524 lines

  1. VERSION 4.00
  2. Begin VB.Form RichForm 
  3.    AutoRedraw      =   -1  'True
  4.    BackColor       =   &H00C0C0C0&
  5.    Caption         =   "Rich"
  6.    ClientHeight    =   5310
  7.    ClientLeft      =   1935
  8.    ClientTop       =   915
  9.    ClientWidth     =   6165
  10.    Height          =   6000
  11.    Left            =   1875
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   5310
  14.    ScaleWidth      =   6165
  15.    Top             =   285
  16.    Width           =   6285
  17.    Begin VB.Frame Frame5 
  18.       Caption         =   "Color"
  19.       Height          =   650
  20.       Left            =   0
  21.       TabIndex        =   18
  22.       Top             =   2450
  23.       Width           =   1935
  24.       Begin VB.Label ColorSwatch 
  25.          BackColor       =   &H00FF00FF&
  26.          Height          =   255
  27.          Index           =   5
  28.          Left            =   1440
  29.          TabIndex        =   24
  30.          Tag             =   "&H00FF00FF"
  31.          Top             =   240
  32.          Width           =   255
  33.       End
  34.       Begin VB.Label ColorSwatch 
  35.          BackColor       =   &H0000FFFF&
  36.          Height          =   255
  37.          Index           =   4
  38.          Left            =   1200
  39.          TabIndex        =   23
  40.          Tag             =   "&H0000FFFF"
  41.          Top             =   240
  42.          Width           =   255
  43.       End
  44.       Begin VB.Label ColorSwatch 
  45.          BackColor       =   &H00FFFF00&
  46.          Height          =   255
  47.          Index           =   3
  48.          Left            =   960
  49.          TabIndex        =   22
  50.          Tag             =   "&H00FFFF00"
  51.          Top             =   240
  52.          Width           =   255
  53.       End
  54.       Begin VB.Label ColorSwatch 
  55.          BackColor       =   &H0000FF00&
  56.          Height          =   255
  57.          Index           =   2
  58.          Left            =   720
  59.          TabIndex        =   21
  60.          Tag             =   "&H0000FF00"
  61.          Top             =   240
  62.          Width           =   255
  63.       End
  64.       Begin VB.Label ColorSwatch 
  65.          BackColor       =   &H000000FF&
  66.          Height          =   255
  67.          Index           =   1
  68.          Left            =   480
  69.          TabIndex        =   20
  70.          Tag             =   "&H000000FF"
  71.          Top             =   240
  72.          Width           =   255
  73.       End
  74.       Begin VB.Label ColorSwatch 
  75.          BackColor       =   &H00000000&
  76.          Height          =   255
  77.          Index           =   0
  78.          Left            =   240
  79.          TabIndex        =   19
  80.          Tag             =   "&H80000012"
  81.          Top             =   240
  82.          Width           =   255
  83.       End
  84.    End
  85.    Begin VB.Frame Frame4 
  86.       Caption         =   "Alignment"
  87.       Height          =   1095
  88.       Left            =   0
  89.       TabIndex        =   14
  90.       Top             =   4220
  91.       Width           =   1935
  92.       Begin VB.OptionButton AlignOption 
  93.          Caption         =   "Center"
  94.          Height          =   255
  95.          Index           =   2
  96.          Left            =   240
  97.          TabIndex        =   17
  98.          Top             =   720
  99.          Width           =   1600
  100.       End
  101.       Begin VB.OptionButton AlignOption 
  102.          Caption         =   "Right"
  103.          Height          =   255
  104.          Index           =   1
  105.          Left            =   240
  106.          TabIndex        =   16
  107.          Top             =   480
  108.          Width           =   1600
  109.       End
  110.       Begin VB.OptionButton AlignOption 
  111.          Caption         =   "Left"
  112.          Height          =   255
  113.          Index           =   0
  114.          Left            =   240
  115.          TabIndex        =   15
  116.          Top             =   240
  117.          Value           =   -1  'True
  118.          Width           =   1600
  119.       End
  120.    End
  121.    Begin VB.Frame Frame3 
  122.       Caption         =   "Paragraph"
  123.       Height          =   1095
  124.       Left            =   0
  125.       TabIndex        =   10
  126.       Top             =   3105
  127.       Width           =   1935
  128.       Begin VB.CheckBox ParaCheck 
  129.          Caption         =   "Hanging"
  130.          Height          =   255
  131.          Index           =   2
  132.          Left            =   240
  133.          TabIndex        =   13
  134.          Top             =   720
  135.          Width           =   1600
  136.       End
  137.       Begin VB.CheckBox ParaCheck 
  138.          Caption         =   "Indent"
  139.          Height          =   255
  140.          Index           =   1
  141.          Left            =   240
  142.          TabIndex        =   12
  143.          Top             =   480
  144.          Width           =   1600
  145.       End
  146.       Begin VB.CheckBox ParaCheck 
  147.          Caption         =   "Bullet"
  148.          Height          =   255
  149.          Index           =   0
  150.          Left            =   240
  151.          TabIndex        =   11
  152.          Top             =   240
  153.          Width           =   1600
  154.       End
  155.    End
  156.    Begin VB.Frame Frame2 
  157.       Caption         =   "Style"
  158.       Height          =   1335
  159.       Left            =   0
  160.       TabIndex        =   5
  161.       Top             =   1100
  162.       Width           =   1935
  163.       Begin VB.CheckBox StyleCheck 
  164.          Caption         =   "Underline"
  165.          Height          =   255
  166.          Index           =   3
  167.          Left            =   240
  168.          TabIndex        =   9
  169.          Top             =   960
  170.          Width           =   1095
  171.       End
  172.       Begin VB.CheckBox StyleCheck 
  173.          Caption         =   "Strikethru"
  174.          Height          =   255
  175.          Index           =   2
  176.          Left            =   240
  177.          TabIndex        =   8
  178.          Top             =   720
  179.          Width           =   1095
  180.       End
  181.       Begin VB.CheckBox StyleCheck 
  182.          Caption         =   "Italic"
  183.          Height          =   255
  184.          Index           =   1
  185.          Left            =   240
  186.          TabIndex        =   7
  187.          Top             =   480
  188.          Width           =   1095
  189.       End
  190.       Begin VB.CheckBox StyleCheck 
  191.          Caption         =   "Bold"
  192.          Height          =   255
  193.          Index           =   0
  194.          Left            =   240
  195.          TabIndex        =   6
  196.          Top             =   240
  197.          Width           =   1095
  198.       End
  199.    End
  200.    Begin VB.Frame Frame1 
  201.       Caption         =   "Font"
  202.       Height          =   1095
  203.       Left            =   0
  204.       TabIndex        =   1
  205.       Top             =   0
  206.       Width           =   1935
  207.       Begin VB.OptionButton FontOption 
  208.          Caption         =   "Times New Roman"
  209.          Height          =   255
  210.          Index           =   2
  211.          Left            =   240
  212.          TabIndex        =   4
  213.          Top             =   720
  214.          Width           =   1660
  215.       End
  216.       Begin VB.OptionButton FontOption 
  217.          Caption         =   "Courier New"
  218.          Height          =   255
  219.          Index           =   1
  220.          Left            =   240
  221.          TabIndex        =   3
  222.          Top             =   480
  223.          Width           =   1660
  224.       End
  225.       Begin VB.OptionButton FontOption 
  226.          Caption         =   "Arial"
  227.          Height          =   255
  228.          Index           =   0
  229.          Left            =   240
  230.          TabIndex        =   2
  231.          Top             =   240
  232.          Value           =   -1  'True
  233.          Width           =   1660
  234.       End
  235.    End
  236.    Begin RichtextLib.RichTextBox RichText 
  237.       Height          =   5295
  238.       Left            =   1980
  239.       TabIndex        =   0
  240.       Top             =   0
  241.       Width           =   4155
  242.       _Version        =   65536
  243.       _ExtentX        =   7329
  244.       _ExtentY        =   9340
  245.       _StockProps     =   69
  246.       BackColor       =   -2147483643
  247.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  248.          name            =   "Arial"
  249.          charset         =   0
  250.          weight          =   400
  251.          size            =   8.25
  252.          underline       =   0   'False
  253.          italic          =   0   'False
  254.          strikethrough   =   0   'False
  255.       EndProperty
  256.       HideSelection   =   0   'False
  257.       ScrollBars      =   3
  258.       TextRTF         =   $"RICH.frx":0000
  259.       BulletIndent    =   360
  260.    End
  261.    Begin VB.Menu mnuFile 
  262.       Caption         =   "&File"
  263.       Begin VB.Menu mnuFileExit 
  264.          Caption         =   "E&xit"
  265.       End
  266.    End
  267. End
  268. Attribute VB_Name = "RichForm"
  269. Attribute VB_Creatable = False
  270. Attribute VB_Exposed = False
  271. Option Explicit
  272.  
  273. Const MAX_FONT = 2
  274. Const MAX_STYLE = 3
  275. Const MAX_PARA = 2
  276. Const MAX_ALIGN = 2
  277.  
  278. Dim SettingValues As Boolean
  279.  
  280. Const PARA_NONE = 0
  281. Const PARA_BULLET = 1
  282. Const PARA_INDENT = 2
  283. Const PARA_HANGING = 3
  284. Dim ParaStyle As Integer
  285.  
  286. Sub CheckParagraphOptions()
  287. Dim i As Integer
  288.  
  289.     SettingValues = True
  290.     
  291.     ' Bullet.
  292.     If IsNull(RichText.SelBullet) Then
  293.         ParaCheck(0).Value = vbGrayed
  294.     ElseIf RichText.SelBullet Then
  295.         ParaCheck(0).Value = vbChecked
  296.     Else
  297.         ParaCheck(0).Value = vbUnchecked
  298.     End If
  299.     
  300.     ' Indent.
  301.     If RichText.SelIndent > 0 Then
  302.         ParaCheck(1).Value = vbChecked
  303.     Else
  304.         ParaCheck(1).Value = vbUnchecked
  305.     End If
  306.     
  307.     ' Hanging indent.
  308.     If RichText.SelHangingIndent > 0 Then
  309.         ParaCheck(2).Value = vbChecked
  310.     Else
  311.         ParaCheck(2).Value = vbUnchecked
  312.     End If
  313.     
  314.     ' Select the correct alignment.
  315.     Select Case RichText.SelAlignment
  316.         Case rtfLeft
  317.             AlignOption(0).Value = True
  318.         Case rtfRight
  319.             AlignOption(1).Value = True
  320.         Case rtfCenter
  321.             AlignOption(2).Value = True
  322.         Case Else
  323.             For i = 0 To MAX_ALIGN
  324.                 AlignOption(i).Value = False
  325.             Next i
  326.     End Select
  327.  
  328.     SettingValues = False
  329. End Sub
  330.  
  331. Private Sub AlignOption_Click(Index As Integer)
  332.     Select Case Index
  333.         Case 0
  334.             RichText.SelAlignment = rtfLeft
  335.         Case 1
  336.             RichText.SelAlignment = rtfRight
  337.         Case 2
  338.             RichText.SelAlignment = rtfCenter
  339.     End Select
  340. End Sub
  341.  
  342. Private Sub ColorSwatch_Click(Index As Integer)
  343.     RichText.SelColor = CLng(ColorSwatch(Index).Tag)
  344. End Sub
  345.  
  346. Private Sub FontOption_Click(Index As Integer)
  347.     RichText.SelFontName = FontOption(Index).Caption
  348. End Sub
  349.  
  350. Private Sub Form_Load()
  351. Dim txt(1 To 6) As String
  352. Dim all As String
  353. Dim i As Integer
  354. Dim offset As Integer
  355.  
  356.     txt(1) = _
  357.     "The 32-bit versions of Visual Basic 4.0 includes " & _
  358.     "the RichTextBox control. This control is similar " & _
  359.     "to a text box but it is much more powerful. A rich " & _
  360.     "text box can display multiple colors, fonts, and " & _
  361.     "styles. It also includes a collection of useful " & _
  362.     "text processing features like:" & vbCrLf
  363.  
  364.     txt(2) = "Paragraph alignment" & vbCrLf
  365.     txt(3) = "Indentation" & vbCrLf
  366.     txt(4) = "Hanging indentation" & vbCrLf
  367.     txt(5) = "Bullets" & vbCrLf
  368.     txt(6) = "Etc." & vbCrLf
  369.  
  370.     For i = 1 To 6
  371.         all = all & txt(i)
  372.     Next i
  373.     RichText.Text = all
  374.  
  375.     offset = Len(txt(1))
  376.     For i = 2 To 6
  377.         RichText.SelStart = offset
  378.         offset = offset + Len(txt(i))
  379.         RichText.SelLength = 1
  380.         RichText.SelBullet = True
  381.     Next i
  382. End Sub
  383.  
  384. ' ***********************************************
  385. ' make the text box as big as possible.
  386. ' ***********************************************
  387. Private Sub Form_Resize()
  388.     RichText.Move Frame1.Width + 1, 0, ScaleWidth - Frame1.Width - 1, ScaleHeight
  389.     RichText.RightMargin = RichText.Width - 120
  390. End Sub
  391.  
  392.  
  393.  
  394.  
  395.  
  396. Private Sub mnuFileExit_Click()
  397.     Unload Me
  398. End Sub
  399.  
  400. Private Sub ParaCheck_Click(Index As Integer)
  401. Dim v As Boolean
  402.  
  403.     If SettingValues Then Exit Sub
  404.     
  405.     v = (ParaCheck(Index).Value = vbChecked)
  406.     Select Case Index
  407.         Case 0
  408.             RichText.SelBullet = v
  409.         Case 1
  410.             If v Then
  411.                 RichText.SelIndent = 360
  412.             Else
  413.                 RichText.SelIndent = 0
  414.             End If
  415.         Case 2
  416.             If v Then
  417.                 RichText.SelHangingIndent = 360
  418.             Else
  419.                 RichText.SelHangingIndent = 0
  420.             End If
  421.     End Select
  422.  
  423.     ' Update the check box values.
  424.     CheckParagraphOptions
  425. End Sub
  426.  
  427.  
  428. ' ************************************************
  429. ' The selection or insertion point has changed.
  430. ' If there is a selection, activate the
  431. ' appropriate menu items.
  432. ' ************************************************
  433. Private Sub RichText_SelChange()
  434. Dim i As Integer
  435.  
  436.     SettingValues = True
  437.     
  438.     If RichText.SelLength <= 0 Then
  439.         ' No text is selected.
  440.         ' Disable the choices.
  441.         For i = 0 To MAX_FONT
  442.             FontOption(i).Enabled = False
  443.             FontOption(i).Value = False
  444.         Next i
  445.         For i = 0 To MAX_STYLE
  446.             StyleCheck(i).Enabled = False
  447.             StyleCheck(i).Value = vbUnchecked
  448.         Next i
  449.     Else
  450.         ' There is a selection.
  451.         For i = 0 To MAX_FONT
  452.             FontOption(i).Enabled = True
  453.             FontOption(i).Value = False
  454.         Next i
  455.         For i = 0 To MAX_STYLE
  456.             StyleCheck(i).Enabled = True
  457.         Next i
  458.         
  459.         ' Select the correct font.
  460.         Select Case RichText.SelFontName
  461.             Case "Arial"
  462.                 FontOption(0).Value = True
  463.             Case "Courier New"
  464.                 FontOption(1).Value = True
  465.             Case "Times New Roman"
  466.                 FontOption(2).Value = True
  467.         End Select
  468.         
  469.         ' Select the correct styles.
  470.         If IsNull(RichText.SelBold) Then
  471.             StyleCheck(0).Value = vbGrayed
  472.         ElseIf RichText.SelBold Then
  473.             StyleCheck(0).Value = vbChecked
  474.         Else
  475.             StyleCheck(0).Value = vbUnchecked
  476.         End If
  477.         If IsNull(RichText.SelItalic) Then
  478.             StyleCheck(1).Value = vbGrayed
  479.         ElseIf RichText.SelItalic Then
  480.             StyleCheck(1).Value = vbChecked
  481.         Else
  482.             StyleCheck(1).Value = vbUnchecked
  483.         End If
  484.         If IsNull(RichText.SelStrikethru) Then
  485.             StyleCheck(2).Value = vbGrayed
  486.         ElseIf RichText.SelStrikethru Then
  487.             StyleCheck(2).Value = vbChecked
  488.         Else
  489.             StyleCheck(2).Value = vbUnchecked
  490.         End If
  491.         If IsNull(RichText.SelUnderline) Then
  492.             StyleCheck(3).Value = vbGrayed
  493.         ElseIf RichText.SelUnderline Then
  494.             StyleCheck(3).Value = vbChecked
  495.         Else
  496.             StyleCheck(3).Value = vbUnchecked
  497.         End If
  498.     End If
  499.  
  500.     SettingValues = False
  501.     
  502.     ' Select the correct paragraph options.
  503.     CheckParagraphOptions
  504. End Sub
  505. Private Sub StyleCheck_Click(Index As Integer)
  506. Dim v As Boolean
  507.  
  508.     If SettingValues Then Exit Sub
  509.     
  510.     v = (StyleCheck(Index).Value = vbChecked)
  511.     Select Case Index
  512.         Case 0
  513.             RichText.SelBold = v
  514.         Case 1
  515.             RichText.SelItalic = v
  516.         Case 2
  517.             RichText.SelStrikethru = v
  518.         Case 3
  519.             RichText.SelUnderline = v
  520.     End Select
  521. End Sub
  522.  
  523.  
  524.